package Visitor;

import Arbori.Nod;
import Functii.*;
import Functii.Elementare.*;
import Functii.Trigonometrice.*;
import Operator.*;

public class ToStringVisitor extends Visitor{
	String s;
	public ToStringVisitor(){
		this.s = "";
	}
	public ToStringVisitor(String s){
		this.s = s;
	}
	
	public String getS() {
		return s;
	}
	public void setS(String s) {
		this.s = s;
	}
	public void visit(Plus p) {
		visitO(p);
	}

	public void visit(Minus m) {
		visitO(m);
	}

	public void visit(Produs p) {
		visitO(p);
	}

	public void visit(Cat c) {
		visitO(c);
	}
	
	public void visitO(Operator o){
		if(o.getfStang() != null && o.getfDrept() != null){
			visit(o.getfStang());
			String s1 = this.s;
			visit(o.getfDrept());
			String s2 = this.s;
			s = o.concatTermeni(s1, s2);
		}
		System.out.println(s);
	}

	public void visitF(Functie f) {
		if(f.getfStang() != null){
			visit(f.getfStang());
			String s1 = this.s;
			s = f.concatTermeni(s1);
		}
		System.out.println(s);
	}
	
	public void visit(Sin s) {
		visitF(s);
	}

	public void visit(Cos c) {
		visitF(c);
	}

	public void visit(Tg t) {
		visitF(t);
	}

	public void visit(Ctg c) {
		visitF(c);
	}

	public void visit(Arcsin as) {
		visitF(as);
	}

	public void visit(Arccos ac) {
		visitF(ac);
	}

	public void visit(Arctg at) {
		visitF(at);
	}

	public void visit(Arcctg ac) {
		visitF(ac);
	}

	public void visit(Sinh sh) {
		visitF(sh);
	}

	public void visit(Cosh ch) {
		visitF(ch);
	}

	public void visit(Constanta c) {
		this.s = Double.toString(c.getCt());
	}

	public void visit(Necunoscuta n) {
		this.s = "x";
	}

	public void visit(Radical r) {
		visitF(r);
	}

	public void visit(Putere p) {
		visitF(p);
	}

	public void visit(Exp e) {
		visitF(e);
	}

	public void visit(Log l) {
		visitF(l);
	}

	public void visit(Nod n) {
		if(n instanceof Necunoscuta) this.visit((Necunoscuta)n);
		if(n instanceof Constanta) this.visit((Constanta)n);
		if(n instanceof Plus) this.visit((Plus)n);
		if(n instanceof Minus) this.visit((Minus)n);
		if(n instanceof Produs) this.visit((Produs)n);
		if(n instanceof Cat) this.visit((Cat)n);
		if(n instanceof Steluta) this.visit((Steluta)n);
		if(n instanceof Exp) this.visit((Exp)n);
		if(n instanceof Log) this.visit((Log)n);
		if(n instanceof Putere) this.visit((Putere)n);
		if(n instanceof Radical) this.visit((Radical)n);
		if(n instanceof Sin) this.visit((Sin)n);
		if(n instanceof Cos) this.visit((Cos)n);
		if(n instanceof Tg) this.visit((Tg)n);
		if(n instanceof Ctg) this.visit((Ctg)n);
		if(n instanceof Arcsin) this.visit((Arcsin)n);
		if(n instanceof Arccos) this.visit((Arccos)n);
		if(n instanceof Arctg) this.visit((Arctg)n);
		if(n instanceof Arcctg) this.visit((Arcctg)n);
		if(n instanceof Sinh) this.visit((Sinh)n);
		if(n instanceof Cosh) this.visit((Cosh)n);
		
	}

}
